package me.zingon.self.bigdispatcher.runner;

import lombok.extern.slf4j.Slf4j;
import me.zingon.self.bigdispatcher.entity.NacosJob;
import me.zingon.self.bigdispatcher.service.NacosJobService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author ztc 1423047407@qq.com
 * @version 1.0
 * @date 2020-12-30 10:58
 */
@Slf4j
@Component
public class NacosJobRunner implements CommandLineRunner {

    @Autowired
    NacosJobService nacosJobService;

    @Override
    public void run(String... args) throws Exception {
        log.info("加载持久化任务");
        List<NacosJob> jobs = nacosJobService.list(null);
        for(NacosJob job:jobs){
            if(job.getStatus() != 0){
                continue;
            }
            nacosJobService.scheduleJob(job);
        }
    }
}
